<template>
  <div class="dashboard-container app-container" :class="platformSource">
    <h3 style="color: black;">{{sideTitle}}</h3>
    <div class="login-tips" style="color: black;">
      <span>欢迎您，</span>
      <span>{{ nickName}}</span>
    </div>

  </div>
</template>
<script>
import {mapGetters} from 'vuex'
import {checkLogin} from "@/api/system/user";

export default {
  name: 'Home',
  computed: {
    ...mapGetters([
      'name',
      'roles',
      'platformSource',
      'platformName'
    ]),
    sideTitle() {
       return this.platformName
      //  return process.env.VUE_APP_TITLE+'—'+ this.platformName
     // return "天保跨境场所" + this.platformName;
    }
  },
  data() {
    return {
      nickName: this.$store.state.user.userLoginInfo.nickName,
      waitNums: null,
    }
  },
  created() {
    this.initPassWord();
  },
  methods: {
    initPassWord() {
      //判断是否是首次登录
      checkLogin().then(
        response => {
          let user = response.data;
          if (response.code == '200' && user != null && user.loginFlag) {
            this.$alert('首次登录必须重置默认密码', '密码重置', {
              confirmButtonText: '确定',
              type: 'warning',
              callback: action => {
                this.$router.push({path: "/user/profile"});
              }
            });
          }
        }
      );
    },
    gotoDb() {
      this.$router.push({path: "/sys/waitItem"});
    },
    handlerMessage(data) {
      let waitItem = JSON.parse(data);
      console.log(waitItem);
      if (waitItem.type === '2') {
        this.waitNums = waitItem.data;
      } else {
        console.log(waitItem.data);
        let obj = JSON.parse(waitItem.data);
        console.log(obj);
        this.rbNotifyMsg(obj.title, obj.descs);
      }
    },
    join() {
      let ip = window.location.hostname + ":9301";
      const wsuri = 'ws://' + ip + '/tymh?userId=' + this.$store.state.user.customsCode + ":" + this.$store.state.user.name;
      this.ws = new WebSocket(wsuri);
      const self = this;
      this.ws.onopen = function (event) {
        self.text_content = self.text_content + "已经打开连接!" + "\n";
        //self.waitNums=1;
        //self.rbNotifyMsg('连已接','通知');
      };
      this.ws.onmessage = function (event) {
        self.text_content = event.data + "\n";
        self.handlerMessage(self.text_content);
      };
      this.ws.onclose = function (event) {
        self.text_content = self.text_content + "已经关闭连接!" + "\n";
      };
    },
    exit() {
      if (this.ws) {
        this.ws.close();
        this.ws = null;
      }
    },
    rbNotifyMsg(title, msg) {
      const self = this;
      this.$notify({
        title: title,
        dangerouslyUseHTMLString: true,
        message: '<a href="#" style="color:blue;text-decoration:underline;">' + msg + '</a>',
        position: 'bottom-right',
        onClick: function () {
          self.gotoDb();
        }
      });
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

.dashboard {
  &-container {
    height: calc(100vh - 84px);
    width: calc(100%);
    background-size: 100% 100%;
    //background: #fff url('../assets/images/login-background.png') no-repeat center;
    background: #fff url('../assets/images/login_bg.png') no-repeat center;
    background-position: center 16%;
    .login-tips {
      font-size: 22px;
      // color: #46A4CB;
      color: #fff;
      padding: 0 0 0 12%;
      text-shadow: 0 0 3px #f8f8f8;
    }

    h3 {
      // color: #486586;
      color: #fff;
      font-size: 42px;
      text-indent: 12%;
      letter-spacing: 3px;
      text-shadow: 0 0 3px #7aa8df;
      padding: 4% 0 0 0;
      margin-bottom: 1.5%;
      font-family: 'SYS_TITLE';
      font-weight: normal;
    }
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

.SYSTEM {
  background: url('../assets/images/login-background.png') no-repeat center;
  background-position: center 16%;
  .login-tips {
    color: #fff;
  }
  h3 {
    color: #fff;
  }
}
.GUIDE {
  background: url('../assets/images/index_bg_2.png') no-repeat center;
  background-size: cover;
  .login-tips {
    color: #1c4c81;
  }
  h3 {
    color: #486586;
  }
}
.PARK {
  background: url('../assets/images/index_bg_4.png') no-repeat center;
  background-size: cover;
  .login-tips {
    color: #1c4c81;
  }
  h3 {
    color: #486586;
  }
}
.EXCHANGE {
  background: url('../assets/images/index_bg_5.png') no-repeat center;
  background-size: cover;
  .login-tips {
    color: #1c4c81;
  }
  h3 {
    color: #486586;
  }
}
</style>
